package com.mingmen.supplier.activity;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lzy.imagepicker.ImagePicker;
import com.mingmen.supplier.R;
import com.mingmen.supplier.adapter.AuditListAdapter;
import com.mingmen.supplier.adapter.CommodityAdapter;
import com.mingmen.supplier.adapter.CommodityLabelAdapter;
import com.mingmen.supplier.defineview.ClearEditText;
import com.mingmen.supplier.flycotablelayout.flyco.tablayout.SegmentTabLayout;
import com.mingmen.supplier.flycotablelayout.flyco.tablayout.listener.OnTabSelectListener;
import com.mingmen.supplier.flycotablelayout.flyco.tablayout.widget.MsgView;
import com.mingmen.supplier.fragment.ShenHeListFragment;
import com.mingmen.supplier.immersionbar.ImmersionBar;
import com.mingmen.supplier.label.bean.LabelTestBean;
import com.mingmen.supplier.label.recycler.OnItemClickListener;
import com.mingmen.supplier.model.EventBean;
import com.mingmen.supplier.popwindow.PopupWindowCompat;
import com.mingmen.supplier.tabuse.ui.SegmentTabActivity;
import com.mingmen.supplier.tabuse.ui.SimpleCardFragment;
import com.mingmen.supplier.util.ViewFindUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

public class AuditListActivity extends AppCompatActivity {

    //返回按钮
    @BindView(R.id.text_return)
    TextView textReturn;

    CommodityLabelAdapter commodityLabelAdapter;
    private List<LabelTestBean> mListData = new ArrayList<>();

    @BindView(R.id.text_seleall)
    TextView text_seleall;

    @BindView(R.id.text_shenhezhong)
    TextView text_shenhezhong;
    @BindView(R.id.text_yitongguo)
    TextView text_yitongguo;
    @BindView(R.id.text_newyitongguo)
    TextView text_newyitongguo;
    @BindView(R.id.layout_all)
    LinearLayout layout_all;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private ArrayList<Fragment> mFragments2 = new ArrayList<>();

    private String[] mTitles_2 = {"全部", "审核中", "已通过", "已拒绝"};

    private View mDecorView;
    @BindView(R.id.linear_return)
    LinearLayout linear_return;
    private String[] mTitles_3 = {"0", "4", "5", "1"};
    @BindView(R.id.main_search)
    ClearEditText main_search;
    SegmentTabLayout tabLayout_4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audit);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();


        for (String title : mTitles_3) {
            mFragments2.add(ShenHeListFragment.getInstance(title));
        }

        mDecorView = getWindow().getDecorView();

        tabLayout_4 = ViewFindUtils.find(mDecorView, R.id.tl_4);

        tabLayout_4.setTabData(mTitles_2, this, R.id.fl_change, mFragments2);
        main_search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    EventBean eventBean = new EventBean();
                    eventBean.setSendCode(26);
                    eventBean.setSendStr(main_search.getText().toString());
                    EventBus.getDefault().post(eventBean);
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(main_search.getWindowToken(), 0);
                } else if (s.toString().length() < 1) {

                } else {

                }


//                startActivityForResult(intent, resurtResurant);
            }
        });
        main_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                EventBean eventBean = new EventBean();
//                Toast.makeText(NewDingDanListActivity.this, "sdf", Toast.LENGTH_SHORT).show();
                eventBean.setSendCode(25);
                eventBean.setSendStr(main_search.getText().toString());
                EventBus.getDefault().post(eventBean);

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);


                return false;
            }
        });

    }


    @OnClick({R.id.text_return, R.id.text_seleall, R.id.text_shenhezhong, R.id.text_yitongguo, R.id.text_newyitongguo, R.id.linear_return})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {


            case R.id.linear_return:
            case R.id.text_return:
                finish();
                break;
            case R.id.text_seleall:
                text_seleall.setBackground(getResources().getDrawable(R.drawable.shape_blue_normal_bg));
                text_seleall.setTextColor(getResources().getColor(R.color.white));
                text_shenhezhong.setBackground(getResources().getDrawable(R.color.white));
                text_shenhezhong.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));

                text_yitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_yitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                text_newyitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_newyitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                layout_all.setBackground(getResources().getDrawable(R.drawable.shape_blue_bluewhitenormal));

                intent = new Intent("com.mingmen.supplier.fragment.ShenHeListFragment");

                intent.putExtra("state", "0");
                sendBroadcast(intent);
                break;
            case R.id.text_shenhezhong:
                text_shenhezhong.setBackground(getResources().getDrawable(R.drawable.shape_blue_normal_bg));
                text_shenhezhong.setTextColor(getResources().getColor(R.color.white));

                text_seleall.setBackground(getResources().getDrawable(R.color.white));
                text_seleall.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));

                text_yitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_yitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                text_newyitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_newyitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                layout_all.setBackground(getResources().getDrawable(R.drawable.shape_blue_bluewhitenormal));
                break;
            case R.id.text_yitongguo:
                text_yitongguo.setBackground(getResources().getDrawable(R.drawable.shape_blue_normal_bg));
                text_yitongguo.setTextColor(getResources().getColor(R.color.white));

                text_seleall.setBackground(getResources().getDrawable(R.color.white));
                text_seleall.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));

                text_shenhezhong.setBackground(getResources().getDrawable(R.color.white));
                text_shenhezhong.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                text_newyitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_newyitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                layout_all.setBackground(getResources().getDrawable(R.drawable.shape_blue_bluewhitenormal));
                break;
            case R.id.text_newyitongguo:
                text_newyitongguo.setBackground(getResources().getDrawable(R.drawable.shape_blue_normal_bg));
                text_newyitongguo.setTextColor(getResources().getColor(R.color.white));

                text_seleall.setBackground(getResources().getDrawable(R.color.white));
                text_seleall.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));

                text_shenhezhong.setBackground(getResources().getDrawable(R.color.white));
                text_shenhezhong.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                text_yitongguo.setBackground(getResources().getDrawable(R.color.white));
                text_yitongguo.setTextColor(getResources().getColor(R.color.normal_bluetextcolor));
                layout_all.setBackground(getResources().getDrawable(R.drawable.shape_blue_bluewhitenormal));
                break;
        }
    }

    public void onEventMainThread(Integer eventBean) {
        if (eventBean == 19) {
            tabLayout_4.setCurrentTab(1);
        }
    }

}




